import java.util.Arrays;

/**
 * @author LKQ
 * @date 2022/3/1 16:14
 * @description 滑动窗口
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {8};
        solution.getAverages(nums, 10000);
    }
    public int[] getAverages(int[] nums, int k) {
        int n = nums.length;
        // sum最大为10^5 * 10^5，需要用long保存
        long sum = 0;
        int[] ans = new int[n];
        Arrays.fill(ans, -1);
        if (n < 2 * k + 1) {
            return ans;
        }
        for (int i = 0; i < n; i++) {
            sum += nums[i];
            if (i >= 2 * k ) {
                ans[i- k] = (int) (sum / (2 * k + 1));
                sum -= nums[i- 2*k];
            }
        }
        return ans;
    }
}
